import { Module } from '@nestjs/common';
import { AmqpService } from './amqp.service';
import { AmqpClientModule } from '@app/amqp-client';
import { CacheModule } from '@app/cache';
import { ConfigureModule, ConfigureService } from '@app/configure';
import { TypeOrmModule } from '@nestjs/typeorm';
import { DeviceRepositoryModule } from '@app/db/device-repository/device-repository.module';

@Module({
	imports: [
		ConfigureModule.forRoot(),
		CacheModule,
		TypeOrmModule.forRootAsync({
			imports : [ConfigureModule],
			inject : [ConfigureService],
			useFactory : (config:ConfigureService) => {
				return {
					...config.get('db')
				}
			},
		}),
		
		AmqpClientModule.forRootAsync({

			inject : [ConfigureService],
			useFactory : async (config:ConfigureService) => {

				const conf = config.get('alicloud')
				return {
					uid : conf.uid, //账号id 您可登录物联网平台控制台，移动鼠标指针到账号头像，查看账号ID。
					accessKeyId : conf.accessKeyId,
					iotInstanceId : conf.iotInstanceId,
					accessKeySecret : conf.accessKeySecret,
					regionId : conf.regionId, //请替换为您的物联网平台设备所在地域的Region ID。Region ID表达方法，请参见支持的地域。
					consumerGroupId : conf.consumerGroupId,
				}
			}
		}),

		DeviceRepositoryModule,
	],
	providers: [AmqpService],
})
export class AmqpModule {}
